import ticker
import bidder

import time
import pdb

IDENT = 'autobot: '

#this is a single bid amount: we buy, we sell this amount
CHUNK_USD = 0.5
CHUNK_LTC = 0.5
#this is a percent stemp up/down from a winner bid
PERCENT_STEP = 0.01

SLEEP_SECS = 10


def main():
    while True:
        noAnyBidFlag, winner, isParent = bidder.runActiveBids()
        if noAnyBidFlag:
            baseRate = ticker.getticker()['last']
            bidder.bidpair(baseRate, CHUNK_LTC, CHUNK_USD, PERCENT_STEP)
            continue
        if not winner:
            print IDENT + 'noone won: sleep ' + str(SLEEP_SECS) + 'secs ...'
            time.sleep(SLEEP_SECS)
            continue
        if isParent:
            if winner.rm_id > 0: bidder.bidrm(winner.rm_id)
            bidder.bidpair(winner.rate, CHUNK_LTC, CHUNK_USD, PERCENT_STEP, winner.type)

if __name__ == '__main__':
    bidder.reset()
    main()
